package org.mbds.wolf.android.hce.seservice;

import java.util.HashMap;

import org.xmlpull.v1.XmlPullParser;

import android.content.Context;

/**
 * This class is intended to get available SE services declared in the XML file declared 
 * in the manifest for HCE service(s).
 * >>>>>Under construction: Not used!<<<<<
 * @author alesas
 *
 */
public class WolfHceMetadata 
{
	
	private HashMap<String, Object> groups = new HashMap<String, Object>();
	private String description;
	private boolean requireDeviceUnlock;
	
	public final static String ATTRIBUTE_DESCRIPTION = "android:description";
	public final static String EVENT_HOST_APDU_SERVICE = "host-apdu-service";
	public final static String EVENT_AID_GROUP = "aid-group";
	
	public WolfHceMetadata(Context ctx, int resourceXmlId) //R.xml.myFile
	{
		load(ctx, resourceXmlId);
	}
	
	private void load(Context ctx, int resourceXmlId) 
	{
		try 
		{
            XmlPullParser xpp=ctx.getResources().getXml(resourceXmlId);

            while (xpp.getEventType()!=XmlPullParser.END_DOCUMENT) 
            {
                if (xpp.getEventType()==XmlPullParser.START_TAG) 
                {
                    if (xpp.getName().equals("host-apdu-service")) 
                    {
                    	int count = xpp.getAttributeCount();
                    	for (int i=0; i<count; i++) 
                    	{
                    		groups.put(xpp.getAttributeName(i), xpp.getAttributeValue(i));
                    	}
                    }
                }

                xpp.next();
            }
        } 
		catch (Throwable t) 
		{
           t.printStackTrace();
        }
	}

	/**
	 * getDescription
	 * @return the description
	 */
	public String getDescription() 
	{
		return description;
	}

	/**
	 * setDescription
	 * @param description the description to set
	 */
	private void setDescription(String description) 
	{
		this.description = description;
	}

	/**
	 * isRequireDeviceUnlock
	 * @return the requireDeviceUnlock
	 */
	public boolean isRequireDeviceUnlock() 
	{
		return requireDeviceUnlock;
	}

	/**
	 * setRequireDeviceUnlock
	 * @param requireDeviceUnlock the requireDeviceUnlock to set
	 */
	private void setRequireDeviceUnlock(boolean requireDeviceUnlock) 
	{
		this.requireDeviceUnlock = requireDeviceUnlock;
	}
}
